/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.util.TimerTask;

// this class is used for gate's delay 
public class ActionDelay extends TimerTask implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private CommonGate gate;
	private int i = 0;

	// constructor. Eclipse wants it, so here it is.
	public ActionDelay() {
	};

	// here I take gate which uses the delay and save it in a private field.
	public ActionDelay(CommonGate gate) {
		this.gate = gate;
	}

	// this method is override from the class TimerTask. Is called every time
	// the timeout expire and it sets
	// the new exit value of the gate.
	// the "i" is used like a counter to use all the signal the gate receives as
	// input. Need this
	// due to the difference in time between the read on the output and the
	// computation of the new value.

	public void run() {
		
		try{
		gate.setIndex(i);
		gate.setNewValue();
		i++;}
		catch(Exception e){}}


}
